package com.uzx.db;

import java.io.IOException;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema;

public class UZXDaoGenerator {

	/**
	 * @param args
	 * @throws Exception 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException, Exception {
		new UZXDaoGenerator().generate();
		
	}
	
	public static final String PACKAGE = "com.fanchuan.uzx.db";
	public static final int VERSION = 1;  //plus one to update database
	
	private Schema mSchema = null;
	public UZXDaoGenerator(){
		mSchema = new Schema(VERSION, PACKAGE);
	}
	
	public void addOfferTable(){
		Entity newTable = mSchema.addEntity("OfferDB");
        newTable.addLongProperty("_id").columnName("_id").primaryKeyAsc().autoincrement();
        newTable.addLongProperty("id");     // the offer id unique
		newTable.addStringProperty("title");
		newTable.addStringProperty("time");
		newTable.addStringProperty("content");
		newTable.addIntProperty("page");
		
	}

	public void addLectureTable(){
		Entity newTable = mSchema.addEntity("LectureDB");
        newTable.addLongProperty("_id").columnName("_id").primaryKeyAsc().autoincrement();
        newTable.addLongProperty("id");     // the offer id unique
		newTable.addStringProperty("title");
		newTable.addStringProperty("time");
		newTable.addStringProperty("content");
		newTable.addIntProperty("page");
	}
	
	public void addNewsTable(){
		Entity newTable = mSchema.addEntity("NewsDB");
        newTable.addLongProperty("_id").columnName("_id").primaryKeyAsc().autoincrement();
        newTable.addLongProperty("id");     // the offer id unique
		newTable.addStringProperty("title");
		newTable.addStringProperty("time");
		newTable.addStringProperty("content");
		newTable.addIntProperty("page");
	}
	
	public void generate() throws IOException, Exception {
		addOfferTable();
		addLectureTable();
		addNewsTable();
		
        DaoGenerator daoGenerator = new DaoGenerator();
		daoGenerator.generateAll(mSchema, "../UZX/gen-db");

	}
	
}
